<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('上架任务管理')" />

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <input type="hidden" id="cjsj_start" name="cjsj_start">
                    <input type="hidden" id="cjsj_end" name="cjsj_end">
                    <input type="hidden" id="shsj_start" name="shsj_start">
                    <input type="hidden" id="shsj_end" name="shsj_end">
                    <div class="layui-inline">
                        <label class="layui-form-label">ASN编号</label>
                        <input type="text" class="layui-input" id="asnbh" name="asnbh" placeholder="ASN编号"/>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">PO编号</label>
                        <input type="text" class="layui-input" id="dycgdbh" name="dycgdbh" placeholder="PO编号"/>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">供应商名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="gysid" name="gysid" placeholder="供应商名称"/>
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal search_btn" lay-event="searchEvent" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">创建时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="cjsj" name="cjsj" placeholder="请选择时间范围" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">收货时间</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="shsj" name="shsj" placeholder="请选择时间范围" />
                            </div>
                        </div>
                    </div>
                </form>

                <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>

<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn{
        width:50px;
        height:20px;
        text-align:center;
        color:#fff;
        line-height:20px;
        background-color:#eee;
        position:relative;
        margin: 0 auto;
        cursor: pointer;
    }
    .moreBtn:before{
        content:'';
        display:block;
        width:35px;
        height:20px;
        position:absolute;
        transform:skewX(30deg);
        background:#eee;
        border-top-left-radius:8px;
        left:-20px;
        top:0;
    }
    .moreBtn:after{
        content:'';
        display:block;
        width:35px;
        height:20px;
        position:absolute;
        transform:skewX(-30deg);
        background:#eee;
        border-top-right-radius:8px;
        top:0;
        right:-20px;
    }
</style>
<script th:inline="javascript">
    var functions = [[${functions}]];
    $(function () {
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        });
        $("#load").on("click",function(){
            //console.log(123);
            var data = {
                ids:[],
                page:0,
                rows:10
            };
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://localhost:9191/zxsdwms/WmsDeliveryDetailsController/ShippingdetailsExcel", true);
            xhr.responseType = "blob";
            xhr.setRequestHeader('Accept', 'application/json');
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.setRequestHeader('Charset', 'utf-8');
            xhr.onload = function() {
                if (this.status == 200) {
                    var name = xhr.getResponseHeader("Content-disposition");
                    name=decodeURI(name);
                    var filename = name.substring(20,name.length);
                    var blob = new Blob([xhr.response], {type: 'text/xls'});
                    var csvUrl = URL.createObjectURL(blob);
                    var link = document.createElement('a');
                    link.href = csvUrl;
                    link.download = filename;
                    link.click();
                }
            };
            xhr.send(JSON.stringify({
                "ids": [],
                "page":0,
                "rows":10
            }));
        })
    });
    layui.use(['list','layer','zzpUtils','jquery','laydate','tablebutton'],function () {
        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        tablebtn = layui.tablebutton;
        var $table;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                //生成
                scsjrwEvent: function (data) {
                    scDialog(data);
                },
                //查看
                getEvent: function (data) {
                    if (data.row != undefined) {
                        getDialog(data);
                    }
                }

            }
        });
        //初始化
        //初始化
        zzpUtils.webSocket.init();
        //创建时间转换时间戳
        laydate.render({
            elem: '#cjsj',
            type: 'date',
            range: '~',
            done: function(value, date, endDate){
                if(value!=null && value!=""){
                    var start=value.toString().substring(0,value.toString().indexOf("~"));
                    var end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#cjsj_start").val(Date.parse(new Date(start)));
                    $("#cjsj_end").val(Date.parse(new Date(end)));
                }else {
                    $("#cjsj_start").val("");
                    $("#cjsj_end").val("");
                }

                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });
        //收货时间转换时间戳
        laydate.render({
            elem: '#shsj',
            type: 'date',
            range: '~',
            done: function(value, date, endDate){
                if(value!=null && value!=""){
                    var start=value.toString().substring(0,value.toString().indexOf("~"));
                    var end=value.toString().substring(value.toString().indexOf("~")+1);
                    $("#shsj_start").val(Date.parse(new Date(start)));
                    $("#shsj_end").val(Date.parse(new Date(end)));
                }else {
                    $("#shsj_start").val("");
                    $("#shsj_end").val("");
                }

                console.log(value); //得到日期生成的值，如：2017-08-18
                console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
            }
        });

        //生成上架任务
        function scDialog(data) {
            var yqdhbdid=data.row.yqdhbdid;
            zzpUtils.dialog({
                title: "生成上架任务",
                type: 2,
                content: "/shelvesRouter/toAddShelvesRw?yqdhbdid="+yqdhbdid,
                area: ['60%', '60%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }

            });
        }
        //查看
        function getDialog(data) {
            var yqdhbdid=data.row.id;
            zzpUtils.dialog({
                title: "查看任务详情",
                type: 2,
                content: "/shelvesRouter/toChakanMx?yqdhbdid=" + yqdhbdid,
                area: ['70%', '70%'], //设置dialog大小，也可以不设置，
            });
        }
        //查询列表
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            isOperate: true,
            functions: functions.tableBtn,
            url: '/wmsshelves/list',
            columns: [
                {
                    field: 'ckmc',
                    title: '仓库'
                }, {
                    field: 'hzmc',
                    title: '货主'
                },  {
                    field: 'asnbh',
                    title: 'ASN编号'
                },{
                    field: 'show_zjzt',
                    title: '质检状态'
                },{
                    field: 'show_asnlx',
                    title: 'ASN类型',
                    visible:false
                },  {
                    field: 'show_asnzt',
                    title: 'ASN状态',
                    visible:false
                },{
                    field: 'show_yxj',
                    title: '优先级',
                    visible:false
                },{
                    field: 'cjsj',
                    title: '创建时间',
                    visible:false,
                    sortable: true,
                    //——修改——获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }
                }, {
                    field: 'zdr',
                    title: '制单人',
                    visible:false
                },  {
                    field: 'ddshr',
                    title: '审核人',
                    visible:false
                },{
                    field: 'shsj',
                    title: '收货时间',
                    visible:false,
                    sortable: true,
                    //——修改——获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }
                },{
                    field: 'dycgdbh',
                    title: 'PO编号',
                    visible:false
                },{
                    field: 'show_gysid',
                    title: '供应商',
                    visible:false
                },{
                    field: 'yjdhsjks',
                    title: '预计到货时间-起',
                    visible:false,
                    sortable: true,
                    //——修改——获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }
                },{
                    field: 'yjdhsjjs',
                    title: '预计到货时间-止',
                    visible:false,
                    sortable: true,
                    //——修改——获取日期列的值进行转换
                    formatter: function (value, row, index) {
                        return changeDateFormat(value)
                    }
                },{
                    field: 'show_shzt',
                    title: '审核状态',
                    visible:false
                },{
                    field: 'show_mpzt',
                    title: '码盘状态',
                    visible:false
                }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter
        });
        $(".inline-reset-btn").on('click',function () {
            $('#cjsj_start').val("");
            $('#cjsj_end').val("");
            $('#shsj_start').val("");
            $('#shsj_end').val("");
            $('#gysid').val("");
            $('#dycgdbh').val("");
            $('#asnbh').val("");
        })

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var btn = '', button = '', buttons1 = '', buttons2 = '';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                //更多之外
                buttons1 += '<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + item.event + '">'
                    + item.name
                    + '</button>';
            }

            return buttons1;
        }

        /*表格右侧按钮原来带三个点的*/
        /*function operateFormatter(value, row, index) {
            var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                button += btn;
            }
            button += '</span>'
                + '</div>';
            return button;
        }*/

    });
    //修改——转换日期格式(时间戳转换为datetime格式)
    function changeDateFormat(cellval) {
        if (cellval != null) {
            return cellval.substr(0,19);
        }
    }
</script>
</html>